home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / chktex.lha / chktex / OpSys.c < prev    next >
C/C++ Source or Header  |  1996-04-30  |  6KB  |  278 lines

  1. /*
  2.  *  ChkTeX v1.4, operating system specific code for ChkTeX.
  3.  *  Copyright (C) 1995-96 Jens T. Berger Thielemann
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  Contact the author at:
  20.  *        Jens Berger
  21.  *        Spektrumvn. 4
  22.  *        N-0666 Oslo
  23.  *        Norway
  24.  *        E-mail: <jensthi@ifi.uio.no>
  25.  *
  26.  *
  27.  */
  28.  
  29.  
  30. /*
  31.  * Some functions which have to be made different from OS to OS,
  32.  * unfortunately...:\
  33.  *
  34.  */
  35.  
  36. #ifdef AMIGA
  37. #    define    __USE_SYSBASE
  38. #    include <dos.h>
  39. #    include <dos/dos.h>
  40. #    include <dos/dosasl.h>
  41. #    include <proto/dos.h>
  42. #    include <proto/exec.h>
  43. #    include <signal.h>
  44. #endif
  45.  
  46. #include "ChkTeX.h"
  47.  
  48.  
  49.  
  50.  
  51. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  52.  
  53. #ifdef AMIGA
  54. const char
  55.     VersString [] = "$VER: ChkTeX 1.4 " __AMIGADATE__
  56.     " Copyright (c) 1995-96 Jens T. Berger Thielemann <jensthi@ifi.uio.no>",
  57.     __stdiowin [] = "CON:0/10/640/180/ChkTeX",
  58.     __stdiov37 [] = "/AUTO/CLOSE/WAIT";
  59.  
  60. static
  61.     struct AnchorPath    *AnchorPath = NULL;
  62.  
  63. static void        KillAnchorPath(void);
  64. static STRPTR    InitAnchorPath(STRPTR String);
  65. #endif
  66.  
  67.  
  68. /*
  69.  * This is the name of the global resource file.
  70.  */
  71.  
  72. #ifndef DATADIR
  73. #   ifdef AMIGA
  74. #       define DATADIR  "S:"
  75. #   elif defined(__unix__)
  76. #       define DATADIR "/usr/local/lib/"
  77. #   else
  78. #       define DATADIR
  79. #   endif
  80. #endif
  81. #define RCBASENAME              "chktexrc"
  82. #define LOCALRCFILE             "." RCBASENAME
  83.  
  84. UBYTE   ConfigFile [BUFSIZ] = LOCALRCFILE;
  85.  
  86.  
  87. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  88.  
  89.  
  90. /*
  91.  * Modify this one to suit your needs. In any case, it should fill
  92.  * the ConfigFile (sized BUFLEN) buffer above with full name & path
  93.  * for the configuration file. The macro RCFILE will give you the
  94.  * filename part of the file, if you need that.
  95.  *
  96.  * If you choose to do nothing, only the current directory will be
  97.  * searched.
  98.  *
  99.  */
  100.  
  101.  
  102. enum LookIn
  103. {
  104.     liCurDir,
  105.     liEnvir,
  106.     liUsrDir,
  107.     liSysDir,
  108.     liNFound,
  109.     liMax
  110. };
  111.  
  112.  
  113. void SetupVars(void)
  114. {
  115.     STRPTR Env;
  116. #ifdef __MSDOS__
  117.     STRPTR Ptr;
  118. #endif
  119.     enum LookIn i;
  120.  
  121.     for(i = 0;
  122.     i < liMax;
  123.     i++)
  124.     {
  125.     switch(i)
  126.     {
  127.     case liCurDir:  /* Current directory */
  128.         strcpy(ConfigFile, LOCALRCFILE);
  129.         break;
  130.     case liEnvir:  /* Environment defined */
  131.         if((Env = getenv("CHKTEXRC")))
  132.         {
  133.         strcpy(ConfigFile, Env);
  134.         tackon(ConfigFile, LOCALRCFILE);
  135.         }
  136.         else
  137.         *ConfigFile = 0;
  138.         break;
  139.     case liUsrDir: /* User dir for resource files */
  140. #ifdef AMIGA
  141.         if(DOSBase->dl_lib.lib_Version < 36)
  142.         strcpy(ConfigFile, "S:");
  143.         else
  144.         strcpy(ConfigFile, "ENV:");
  145.  
  146.         tackon(ConfigFile, LOCALRCFILE);
  147. #elif defined(__unix__)
  148.         if((Env = getenv("HOME")))
  149.         {
  150.         strcpy(ConfigFile, Env);
  151.         tackon(ConfigFile, LOCALRCFILE);
  152.         }
  153.         else
  154.         *ConfigFile = 0;
  155. #elif defined(__MSDOS__)
  156.             strcpy(ConfigFile, PrgName);
  157.             if(Ptr = strrchr(ConfigFile, '\\'))
  158.             {
  159.                 strcpy(++Ptr, RCBASENAME);
  160.             }
  161.             else
  162.                 *ConfigFile = 0;
  163. #endif
  164.         break;
  165.     case liSysDir: /* System dir for resource files */
  166. #ifdef __unix__
  167.         if(!fexists(ConfigFile))
  168.         {
  169.         strcpy(ConfigFile, DATADIR);
  170.         tackon(ConfigFile, RCBASENAME);
  171.         }
  172.         else
  173.         *ConfigFile = 0;
  174. #endif
  175.         break;
  176.     case liNFound:
  177.     case liMax:
  178.         PrintPrgErr(pmNoRsrc);
  179.     }
  180.  
  181.     if(*ConfigFile && fexists(ConfigFile))
  182.         break;
  183.     }
  184. }
  185.  
  186. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  187.  
  188. #ifdef AMIGA
  189.  
  190. /*
  191.  * This function should be called first with String being a file pattern.
  192.  * It should then return the first filename matching that pattern.
  193.  * Subsequent calls will be made with String = NULL; it should then return
  194.  * any other filenames that matches the same pattern.
  195.  * If the first call is made with NULL, you should return NULL.
  196.  * It may be called more than once with String != NULL, however, you need
  197.  * only to keep track of the last invocation.
  198.  *
  199.  * Don't assume that the String passed will live on until the next
  200.  * invocation, though. strdup() it if you need it after the first time.
  201.  */
  202.  
  203.  
  204. STRPTR MatchFileName(STRPTR String)
  205. {
  206.     STRPTR    Retval = NULL;
  207.  
  208.     if(AnchorPath || String)    /* Is this the first invocation? */
  209.     {
  210.     if(DOSBase->dl_lib.lib_Version > 36)
  211.     {
  212.         ifn(AnchorPath)
  213.         {
  214.         if(AnchorPath = malloc(sizeof(struct AnchorPath) + FMSIZE))
  215.         {
  216.             Retval = InitAnchorPath(String);
  217.             atexit(&KillAnchorPath);
  218.         }
  219.         }
  220.         else
  221.         {
  222.         if(String)
  223.         {
  224.             MatchEnd(AnchorPath);
  225.             Retval = InitAnchorPath(String);
  226.         }
  227.         else
  228.         {
  229.             ifn(MatchNext(AnchorPath))
  230.             Retval = AnchorPath->ap_Buf;
  231.         }
  232.         }
  233.     }
  234.     else        /* ARP support may be added in the future */
  235.         Retval = String;
  236.  
  237.     if(AnchorPath && AnchorPath->ap_FoundBreak)
  238.         raise(SIGINT);
  239.     }
  240.  
  241.     if(!Retval && String)
  242.     Retval = String;
  243.  
  244.     return(Retval);
  245. }
  246.  
  247. static void KillAnchorPath(void)
  248. {
  249.     MatchEnd(AnchorPath);
  250. }
  251.  
  252. static STRPTR InitAnchorPath(STRPTR String)
  253. {
  254.     STRPTR    Retval = NULL;
  255.  
  256.     AnchorPath->ap_BreakBits = SIGBREAKF_CTRL_C;
  257.     AnchorPath->ap_Strlen = FMSIZE;
  258.     AnchorPath->ap_FoundBreak = FALSE;
  259.     AnchorPath->ap_Flags = 0L;
  260.  
  261.     ifn(MatchFirst(String, AnchorPath))
  262.     Retval = AnchorPath->ap_Buf;
  263.     else
  264.     PrintPrgErr(pmNoFileMatch, String);
  265.  
  266.     AnchorPath->ap_Flags &= ~(APF_DODIR);
  267.     return(Retval);
  268. }
  269.  
  270. #else
  271. STRPTR MatchFileName(STRPTR String)
  272. {
  273.     return(String);
  274. }
  275. #endif
  276.  
  277.  
  278.